# defaultargs.py
#
# Copyright (c) 2006 Michael Hobbs
#
# This file is part of iTorrent.
#
# iTorrent is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# iTorrent is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iTorrent; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


import sys
import os

from BitTorrent.defaultargs import basic_options, common_options, rare_options


def resetDefault(options, option, default):
	for i in xrange(len(options)):
		opt, _, description = options[i]
		if opt == option:
			options[i] = (opt, default, description)
			break
		# end if
	# end for

def remove(options, option):
	for i in xrange(len(options)):
		opt, _, description = options[i]
		if opt == option:
			del options[i]
			break
		# end if
	# end for


patched_basic_options = basic_options[:]
patched_common_options = common_options[:]
patched_rare_options = rare_options[:]

patched_basic_options.append(('control_port', 80, _('port for iTorrent to listen on for control messages')))

# I prefer a default display_interval of 10.
resetDefault(patched_common_options, 'display_interval', 10.0)
# Set data_dir default.
if 'RESOURCEPATH' in os.environ:
	baseDir = os.path.join(os.environ['RESOURCEPATH'], '..', '..', '..')
else:
	baseDir = sys.path[0]
dataDir = os.path.abspath(os.path.join(baseDir, 'data'))
resetDefault(patched_basic_options, 'data_dir', dataDir)
# Rename tracker_proxy option to http_proxy
remove(patched_rare_options, 'tracker_proxy')
patched_rare_options.append(('http_proxy', '', _("URL of proxy to use for HTTP connections")))
